<?php

namespace Drupal\shusy_product\ViewsController;

use Drupal\shusy_product\ViewsController\handler\field\ShusyProductCommentEditLinkViewsField;
use Drupal\shusy_product\ViewsController\handler\field\ShusyProductCommentHasImgViewsField;
use Drupal\shusy_product\ViewsController\handler\field\ShusyProductCommentScoreViewsField;
use Drupal\shusy_product\ViewsController\handler\field\ShusyProductCommentStatusViewsField;
use Drupal\shusy_product\ViewsController\handler\filter\ShusyProductCommentHasImgViewsFilter;
use Drupal\shusy_product\ViewsController\handler\filter\ShusyProductCommentScoreViewsFilter;
use Drupal\shusy_product\ViewsController\handler\filter\ShusyProductCommentStatusViewsFilter;
use EntityDefaultViewsController;


class ShusyProductCommentViewsController extends EntityDefaultViewsController {

  public function views_data() {
    $data = parent::views_data();
    if (!empty($this->info['base table'])) {
      $table = $this->info['base table'];
      $info = [];

      $info[$table]['edit_link'] = [
        'title' => t('编辑'),
        'help' => t('编辑.'),
        'field' => [
          'handler' => ShusyProductCommentEditLinkViewsField::class,
        ],
      ];
      $info[$table]['has_img'] = [
        'title' => '是否有图 0 无图 1 有图',
        'help' => '是否有图 0 无图 1 有图',
        'real field' => 'has_img',
        'field' => [
          'handler' => ShusyProductCommentHasImgViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyProductCommentHasImgViewsFilter::class,
        ],
      ];
      $info[$table]['status'] = [
        'title' => '状态 0 审核中 1 通过 2 未通过',
        'help' => '状态 0 审核中 1 通过 2 未通过',
        'real field' => 'status',
        'field' => [
          'handler' => ShusyProductCommentStatusViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyProductCommentStatusViewsFilter::class,
        ],
      ];
      $info[$table]['score'] = [
        'title' => '评分 1 - 5',
        'help' => '评分 1 - 5',
        'real field' => 'score',
        'field' => [
          'handler' => ShusyProductCommentScoreViewsField::class,
        ],
        'filter' => [
          'handler' => ShusyProductCommentScoreViewsFilter::class,
        ],
      ];
      $data = drupal_array_merge_deep($data, $info);
    }
    return $data;
  }
}
